import { Component, OnInit, Input ,EventEmitter, Output} from '@angular/core';

@Component({
  selector: 'app-rating',
  templateUrl: './rating.component.html',
  styleUrls: ['./rating.component.scss'],
})
export class RatingComponent implements OnInit {
  @Output() updateRate: EventEmitter<any> = new EventEmitter();
  @Input() rate: any;
  @Input() valueCssStyle: any;
  @Input() edit: any; // 表单
  @Input() onlyShow: any; // 表单样式仅展示
  @Input() star_highLight: any; // 图标
  @Input() star_gray: any; // 图标

  stars = [];
  constructor() { }

  ngOnInit() {
    for (let i = 1; i <= 5; i++) {
      this.stars.push(i <= (+this.rate));
    }

  }
  onClick(n) {
    if (this.onlyShow === true) {
      return;
    }
    this.rate = n;
    this.stars = [];
    for (let i = 1; i <= 5; i++) {
      this.stars.push(i <= (+this.rate));
    }
    this.updateRate.emit(n);

  }

}
